<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旅客预测 - 航空旅客付费选座意愿识别系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&family=Poppins:wght@400;600;800&display=swap" rel="stylesheet">
    <style>
        :root {
            --neon-purple: #bf00ff;
            --neon-blue: #0091ff;
            --dark-bg: #12192c;
            --card-bg: rgba(22, 33, 56, 0.85);
        }
        
        body {
            font-family: 'Poppins', 'Noto Sans SC', sans-serif;
            background-color: var(--dark-bg);
            color: white;
            background-image: 
                radial-gradient(circle at 10% 90%, rgba(191, 0, 255, 0.1) 0%, transparent 40%),
                radial-gradient(circle at 90% 10%, rgba(0, 145, 255, 0.1) 0%, transparent 40%);
            min-height: 100vh;
            padding-bottom: 3rem;
        }
        
        .navbar {
            background: rgba(22, 33, 56, 0.8);
            backdrop-filter: blur(10px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .navbar-brand {
            font-weight: 800;
            font-size: 1.5rem;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .navbar-brand i {
            text-shadow: 0 0 10px var(--neon-blue);
        }
        
        .nav-link {
            color: rgba(255, 255, 255, 0.7);
            margin: 0 10px;
            font-weight: 500;
            position: relative;
        }
        
        .nav-link::after {
            content: '';
            position: absolute;
            bottom: -5px;
            left: 0;
            width: 0;
            height: 2px;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
            transition: width 0.3s;
        }
        
        .nav-link:hover, .nav-link.active {
            color: white;
        }
        
        .nav-link:hover::after, .nav-link.active::after {
            width: 100%;
        }
        
        .page-title {
            text-align: center;
            margin: 3rem 0;
            font-weight: 800;
            font-size: 2.5rem;
            background: linear-gradient(135deg, white, #ccc);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            position: relative;
        }
        
        .page-title::after {
            content: '';
            display: block;
            width: 100px;
            height: 3px;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
            margin: 10px auto 0;
            border-radius: 3px;
        }
        
        .card {
            background: var(--card-bg);
            border-radius: 15px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            overflow: hidden;
            position: relative;
            margin-bottom: 2rem;
        }
        
        .card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
        }
        
        .card-header {
            background: transparent;
            padding: 1.5rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .card-header h3 {
            font-weight: 700;
            margin: 0;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .card-header i {
            color: var(--neon-blue);
            text-shadow: 0 0 10px rgba(0, 145, 255, 0.5);
        }
        
        .card-body {
            padding: 2rem;
        }
        
        .model-status {
            background: rgba(30, 41, 59, 0.5);
            border-radius: 10px;
            padding: 1rem;
            margin-bottom: 2rem;
            border: 1px solid rgba(255, 255, 255, 0.05);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .status-indicator {
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background-color: #48bb78;
            box-shadow: 0 0 10px rgba(72, 187, 120, 0.5);
        }
        
        .upload-area {
            border: 2px dashed rgba(255, 255, 255, 0.2);
            border-radius: 15px;
            padding: 4rem 2rem;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-bottom: 2rem;
            position: relative;
            overflow: hidden;
        }
        
        .upload-area::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(0, 145, 255, 0.1), transparent);
            transition: all 0.6s ease;
        }
        
        .upload-area:hover {
            border-color: var(--neon-blue);
            background: rgba(0, 145, 255, 0.05);
        }
        
        .upload-area:hover::before {
            left: 100%;
        }
        
        .upload-icon {
            font-size: 4rem;
            color: var(--neon-blue);
            margin-bottom: 1.5rem;
            text-shadow: 0 0 20px rgba(0, 145, 255, 0.3);
            transition: transform 0.3s ease;
        }
        
        .upload-area:hover .upload-icon {
            transform: scale(1.1) rotate(-5deg);
        }
        
        .btn {
            padding: 0.8rem 2rem;
            border-radius: 8px;
            font-weight: 600;
            transition: all 0.3s ease;
            border: none;
            cursor: pointer;
        }
        
        .btn-gradient {
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
            color: white;
            box-shadow: 0 0 15px rgba(0, 145, 255, 0.3);
        }
        
        .btn-gradient:hover {
            box-shadow: 0 0 25px rgba(0, 145, 255, 0.5);
            transform: translateY(-3px);
        }
        
        .btn-outline {
            background: transparent;
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: white;
        }
        
        .btn-outline:hover {
            background: rgba(255, 255, 255, 0.1);
            border-color: rgba(255, 255, 255, 0.3);
        }
        
        .alert {
            border-radius: 8px;
            padding: 1rem;
            margin-bottom: 1.5rem;
            border: none;
        }
        
        .alert-success {
            background: rgba(72, 187, 120, 0.2);
            color: #48bb78;
            border-left: 4px solid #48bb78;
        }
        
        .alert-danger {
            background: rgba(239, 68, 68, 0.2);
            color: #ef4444;
            border-left: 4px solid #ef4444;
        }
        
        .chart-container {
            height: 350px;
            margin: 2rem 0;
            border-radius: 10px;
            overflow: hidden;
            position: relative;
            background: rgba(0, 0, 0, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .chart-container img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
        
        .result-stats {
            background: rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            padding: 1.5rem;
            margin-bottom: 2rem;
            border: 1px solid rgba(255, 255, 255, 0.05);
        }
        
        .result-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 2rem;
            margin-bottom: 2rem;
        }
        
        .stat-box {
            background: rgba(0, 0, 0, 0.15);
            border-radius: 10px;
            padding: 1.5rem;
            text-align: center;
            border: 1px solid rgba(255, 255, 255, 0.05);
            transition: transform 0.3s ease;
        }
        
        .stat-box:hover {
            transform: translateY(-5px);
        }
        
        .stat-value {
            font-size: 2.5rem;
            font-weight: 800;
            margin: 0.5rem 0;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }
        
        .stat-label {
            color: rgba(255, 255, 255, 0.7);
            font-size: 0.9rem;
        }
        
        footer {
            text-align: center;
            padding: 2rem 0;
            margin-top: 4rem;
            color: rgba(255, 255, 255, 0.5);
            font-size: 0.9rem;
        }
        
        @media (max-width: 768px) {
            .page-title {
                font-size: 2rem;
            }
            
            .card-body {
                padding: 1.5rem;
            }
            
            .upload-area {
                padding: 3rem 1rem;
            }
            
            .chart-container {
                height: 280px;
            }
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg">
        <div class="container">
            <a class="navbar-brand" href="/">
                <i class="fa fa-plane"></i>
                <span>选座预测系统</span>
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <i class="fa fa-bars text-white"></i>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/train">模型训练</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" aria-current="page" href="/predict">旅客预测</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/analysis">数据分析</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container">
        <h1 class="page-title">旅客付费选座预测</h1>
        
        <!-- 消息提示 -->
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, msg in messages %}
                    <div class="alert alert-{{ category }}">
                        <i class="fa fa-{{ 'check-circle' if category == 'success' else 'exclamation-circle' }}"></i> {{ msg }}
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}
        
        <!-- 模型状态提示 -->
        <div class="model-status">
            <div class="status-indicator"></div>
            <span>当前使用已训练的模型进行预测，模型状态正常</span>
        </div>
        
        <div class="row">
            <div class="col-md-10 mx-auto">
                <div class="card">
                    <div class="card-header">
                        <h3><i class="fa fa-users"></i> 旅客数据预测</h3>
                    </div>
                    <div class="card-body">
                        {% if not prediction_done %}
                            <!-- 预测数据上传表单 -->
                            <form method="post" enctype="multipart/form-data">
                                <div class="mb-4">
                                    <div class="upload-area" onclick="document.getElementById('predictFile').click()">
                                        <input type="file" id="predictFile" name="file" accept=".csv" style="display: none;" required>
                                        <div class="upload-icon">
                                            <i class="fa fa-cloud-upload"></i>
                                        </div>
                                        <h4>点击或拖拽旅客数据文件到此处上传</h4>
                                        <p class="text-muted mt-2">支持CSV格式，需与训练数据特征一致</p>
                                    </div>
                                </div>
                                
                                <div class="d-flex justify-content-between">
                                    <button type="submit" class="btn btn-gradient">
                                        <i class="fa fa-line-chart"></i> 开始预测
                                    </button>
                                    <a href="/" class="btn btn-outline">
                                        <i class="fa fa-arrow-left"></i> 返回首页
                                    </a>
                                </div>
                            </form>
                        {% else %}
                            <!-- 预测结果展示 -->
                            <div class="alert alert-success">
                                <i class="fa fa-check-circle me-2"></i>预测完成！共处理 {{ result_count }} 条旅客数据
                            </div>
                            
                            <div class="result-stats">
                                <h4 class="mb-4">预测结果统计</h4>
                                <div class="result-grid">
                                    <div class="chart-container">
                                        <img src="data:image/png;base64,{{ plots.prediction_distribution }}" 
                                             alt="预测结果分布" class="w-100 h-100 object-contain">
                                    </div>
                                    <div class="chart-container">
                                        <img src="data:image/png;base64,{{ plots.probability_distribution }}" 
                                             alt="付费概率分布" class="w-100 h-100 object-contain">
                                    </div>
                                </div>
                            </div>
                            
                            <div class="d-flex flex-wrap gap-2 justify-content-center">
                                <a href="{{ url_for('download_result') }}" class="btn btn-gradient">
                                    <i class="fa fa-download me-1"></i> 下载预测结果
                                </a>
                                <a href="/predict" class="btn btn-outline">
                                    <i class="fa fa-refresh me-1"></i> 重新预测
                                </a>
                                <a href="/analysis" class="btn btn-outline">
                                    <i class="fa fa-bar-chart me-1"></i> 查看数据分析
                                </a>
                                <a href="/" class="btn btn-outline">
                                    <i class="fa fa-home me-1"></i> 返回首页
                                </a>
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <footer>
        <div class="container">
            <p>© 2023 航空旅客付费选座意愿识别系统 | 数据驱动决策支持</p>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 显示上传的文件名
        document.getElementById('predictFile')?.addEventListener('change', function(e) {
            if (e.target.files.length > 0) {
                const fileName = e.target.files[0].name;
                document.querySelector('.upload-area h4').textContent = `已选择文件：${fileName}`;
            }
        });
    </script>
</body>
</html>